#!/usr/bin/perl
package Foo;
use Data::Dumper;

sub new {
    my $class = shift;
    bless{ number => 0 },$class; 
}

use overload
  '""'     => 'self',
  '+'      => 'add',
  '-'      => 'subtrance',
  fallback => 1;

sub self {
    my $self = shift;
    return $self->{number};
}


sub add {
    my $self = shift;
    $self->{number} = $self->{number} + $_[0];
    return $self->{number};
}

sub subtrance {
    my $self = shift;
    $self->{number} = $self->{number} - $_[0];
    return $self->{number};
}

package mail;

my $foo = Foo->new();

print "1>$foo \n";
$foo + 123;
print "+ > $foo \n";
3 + $foo;
print "+ > $foo \n";
$foo - 1;
print "- > $foo \n";


__END__
use Number::Fraction;
use strict;

my $f1 = Number::Fraction->new(1, 2);
my $f2 = Number::Fraction->new('1/4');
my $f3 = Number::Fraction->new($f1); # clone
my $f4 = Number::Fraction->new; # 0/1

print "$f1 \n";
print "$f2 \n";
print "$f3 \n";
print "$f4 \n";

my $f = $f1 + $f2;

print "= $f \n"; #  3/4

